package com.ph.irp.base.assistantmaterial.action;
import java.util.List;
import com.opensymphony.xwork2.ActionSupport;
import com.ph.irp.base.assistantmaterial.service.PBaseAssistantmaterialDutyService;
import com.ph.irp.model.PBaseAssistantmaterialDuty;
public class AssistantmaterialDutyAction extends ActionSupport {
	private PBaseAssistantmaterialDutyService dutyService;
	public void setDutyService(PBaseAssistantmaterialDutyService dutyService) {
		this.dutyService = dutyService;
	}

	private List<PBaseAssistantmaterialDuty> dutys;
//	@SuppressWarnings("unused")
//	private int total;
//	
//	public int  getTotal() throws Throwable{
//		
//		return dutyService.getCount();
//	}
//	
	private PBaseAssistantmaterialDuty duty;
	private Object[] rowlist = null;
	
	public List<PBaseAssistantmaterialDuty> getDutys() {
		return dutys;
	}

	public void setDutys(List<PBaseAssistantmaterialDuty> dutys) {
		this.dutys = dutys;
	}

	public PBaseAssistantmaterialDuty getDuty() {
		return duty;
	}

	public void setDuty(PBaseAssistantmaterialDuty duty) {
		this.duty = duty;
	}

	public Object[] getRowlist() {
		return rowlist;
	}

	public void setRowlist(Object[] rowlist) {
		this.rowlist = rowlist;
	}

	public String showDutyList() throws Throwable {
		duty=null;
		dutys = dutyService.getDutyList();
		return "success";
	}

	public String searchDuty() throws Throwable {
		if(duty==null){
		  dutys = dutyService.getDutyList();	
		}else{
			if(!duty.getDutyCode().equals("")&&!duty.getDutyName().equals("")){
				dutys=dutyService.getDutyByCodeAndName(duty.getDutyCode(), duty.getDutyName());
			}else if(!duty.getDutyCode().equals("")){
				dutys=dutyService.getDutyByCode(duty.getDutyCode());
			}else if(!duty.getDutyName().equals("")){
				dutys=dutyService.getDutyByName(duty.getDutyName());
			}else{
			    dutys = dutyService.getDutyList();	
			}		
		}
		duty = null;
		return "success";
	}
	
	//List页面跳转到add新增页面
	public String addInputDuty()throws Throwable{
		return "success";
	}
	//List页面跳转到update修改页面
	public String updateInputDuty() throws Throwable {
		Integer dutyId = Integer.valueOf((String) rowlist[0]);
		duty = dutyService.getDutyById(dutyId);
		return "success";
	}
	
	public String addDuty() throws Throwable{
		dutyService.addPBaseAssistantmaterialDuty(duty);
		return "success";
	}

	public String updateDuty() throws Throwable{
		dutyService.updatePBaseAssistantmaterialDuty(duty);
		return "success";
	}
	
	public String deleteDuty() throws Throwable{
		for (int i = 0; i < rowlist.length; i++) {
			dutyService.deletePBaseAssistantmaterialDuty(Integer.valueOf((String) rowlist[i]));
		}
		return "success";
	}

	public String selectDuty() throws Throwable{
		if(duty==null){
			  dutys = dutyService.getDutyList();	
			}else{
				if(!duty.getDutyCode().equals("")&&!duty.getDutyName().equals("")){
					dutys=dutyService.getDutyByCodeAndName(duty.getDutyCode(), duty.getDutyName());
				}else if(!duty.getDutyCode().equals("")){
					dutys=dutyService.getDutyByCode(duty.getDutyCode());
				}else if(!duty.getDutyName().equals("")){
					dutys=dutyService.getDutyByName(duty.getDutyName());
				}else{
				    dutys = dutyService.getDutyList();	
				}		
			}
		return "success";
	}
	
}